<script type="text/javascript">        

function Suppliers_Standalone_Success(id){
    selected_supplier = id;
    Load_Suppliers_List();
    $("#suppliers_select").change();
};
                                       
var selected_supplier = '<?=$supplier?>';
var Load_Suppliers_List;
      
$(document).ready(function(){          

    Load_Suppliers_List = function(){ 
		loading_queue++;	
        $('#suppliers_select').html('<option value="">Loading list of suppliers...</option>');
        $.post("<?=site_url("/admin/products/get_suppliers_list")?>", {},
            function(data){
                Refresh_Suppliers_List(data);
						loading_queue--;
            }, "json"
        );
    }           
    function Refresh_Suppliers_List(data){

        var selected = (selected_supplier=='') ? ' selected="selected"' : '';
        var list = '';
        list += '<option value=""'+selected+'>Select a supplier...</option>';  
        list += '<option value="">---------</option>';  
        for ( var i=0; i<data.length; i++ ){
            selected = (selected_supplier==data[i].id) ? ' selected="selected"' : '';
            list += '<option value="'+data[i].id+'"'+selected+'>' +data[i].name+ '</option>';
        }
        $('#suppliers_select').html(list);
        if (selected_supplier!='') Load_Supplier_Info();

    }                                      

    $("#suppliers_select").change(function(){
        if ($(this).val()!='') Load_Supplier_Info();

    })  
    //disable form submition when pressing enter on select
    $("#suppliers_select").bind("keypress", function(e,a) {
        if (e.keyCode == 13) {
            $("#supplier_select_trigger").click();
            return false;
        }
    });

    //var remember = "";
    function Load_Supplier_Info(){

        var id = $('#suppliers_select').val(); 
        $("#supplier_id").val(id);        
        $("#suppliers_select option[value='']").remove();
        selected_supplier = id;
        //remember = $('#supplier_container').html();
        //$('#supplier_container').html("loading supplier...");

        $.post("<?=site_url("/admin/products/get_supplier_info")?>", 
            {id:id},
            function(data){
                Refresh_Supplier_Info(data);
            }, "json"
        );
    }           
    function Refresh_Supplier_Info(data){
          
        //$('#supplier_container').html(remember);                                                    
        $('#supplier_container #Code_Supplier').html(data.Code_Supplier);
        $('#supplier_container #Name_Supplier').html(data.Name_Supplier);
        $('#supplier_container #ContactName_Supplier').html(data.ContactName_Supplier);
        $('#supplier_container #Address_Supplier').html(data.Address_Supplier);
        $('#supplier_container #Phone_Supplier').html(data.Phone_Supplier);
        $('#supplier_container #Fax_Supplier').html(data.Fax_Supplier);
        $('#supplier_container #Mobile_Supplier').html(data.Mobile_Supplier);
        $('#supplier_container #Email_Supplier').html(data.Email_Supplier);
        $('#supplier_container #WebSite_Supplier').html(data.WebSite_Supplier);
        $('#supplier_container #City_Supplier').html(data.City_Supplier);
        $('#supplier_container #Address2_Supplier').html(data.Address2_Supplier);
        $('#supplier_container #State_Supplier').html(data.State_Supplier);
        $('#supplier_container #Country_Supplier').html(data.Country_Supplier);
        $('#supplier_container #PostCode_Supplier').html(data.PostCode_Supplier);

        $('#supplier_container').hide().fadeIn();  

    }                                 

    Load_Suppliers_List();   

    $("#new_supplier_trigger").click(function(){
        var url = '<?=site_url('admin/suppliers/add/standalone')?>';
        var new_window = window.open(url,"supplier_manager","menubar=0,toolbar=0,location=0,status=0,toolbar=0,titlebar=0,scrollbars=1,width=840,height=500"); 
        new_window.focus();
        return false;
    })       

    $("#edit_supplier_trigger").click(function(){
        var url = '<?=site_url('admin/suppliers/edit/')?>/'+selected_supplier+'/standalone';
        var new_window = window.open(url,"supplier_manager","menubar=0,toolbar=0,location=0,status=0,toolbar=0,titlebar=0,scrollbars=1,width=840,height=500"); 
        new_window.focus();
        return false;
    })       

});        

</script>

<div class="content_block">
           
    <h4 class="float_block" style="width:100px">Supplier</h2>
    <select id="suppliers_select" style="float_left" style="min-width:150px">
    </select>
    <input type="hidden" id="supplier_id" name="supplier_id" value="<?=$supplier?>" />
    <a href="#" class="button" id="new_supplier_trigger">ADD NEW SUPPLIER</a>

    <div class="clear"></div>
             
    <h4 class="float_block" style="width:100px; clear:left">Product code</h4>
    <input type="text" style="width: 171px;" name="code" value="<?=set_value('code', $item['Code_Products'])?>" maxlength="36" />

    <div class="clear"></div>

    <h4 class="float_block" style="width:100px">Price</h4>
    <div class="float_block" style="width:92px;">
        <input name="price" type="text" value="<?=set_value('price', $item['Price_Products'])?>" maxlength="36" />
    </div>

    <select name="currency" style="width:74px">
    <? 
    foreach(explode(",",CURRENCY_LIST) as $cur){ 
    ?>     
        <option value="<?=$cur?>" <?=set_select('currency', $cur, ($item['Currency_Products']==$cur))?>><?=$cur?></option>

    <? } ?>
    </select>  
                                                                                
</div>
    
<div id="supplier_container" class="content_block" style="display:none; width:100%; overflow:auto">

    <h3>Supplier details:</h3>

    <div class="hr"></div>

    <div class="float_block" style="width:40%">

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Company</h4>                                    
            <div id="Name_Supplier" style="margin-left:100px"></div>     
        </div>

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Contact Name</h4>                                    
            <div id="ContactName_Supplier" style="margin-left:100px"></div>     
        </div>

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Email</h4>                                    
            <div id="Email_Supplier" style="margin-left:100px"></div>     
        </div>

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Phone</h4>                                    
            <div id="Phone_Supplier" style="margin-left:100px"></div>     
        </div>
    
        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Fax</h4>                                    
            <div id="Fax_Supplier" style="margin-left:100px"></div>     
        </div>             
    
        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Mobile</h4>                                    
            <div id="Mobile_Supplier" style="margin-left:100px"></div>     
        </div>

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Website</h4>                                    
            <div id="WebSite_Supplier" style="margin-left:100px"></div>     
        </div>                    
    
    </div>


    <div class="float_block" style="width:40%">
                                                                        
        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Supplier code</h4>                                    
            <div id="Code_Supplier" style="margin-left:100px"></div>     
        </div>  

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Address</h4>                                    
            <div id="Address_Supplier" style="margin-left:100px"></div>     
        </div>                 

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">City</h4>                                    
            <div id="City_Supplier" style="margin-left:100px"></div>     
        </div>                 

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">State</h4>                                    
            <div id="State_Supplier" style="margin-left:100px"></div>     
        </div>                 

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Post Code</h4>                                    
            <div id="PostCode_Supplier" style="margin-left:100px"></div>     
        </div>                 

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Country</h4>                                    
            <div id="Country_Supplier" style="margin-left:100px"></div>     
        </div>                 

        <div class="float_block" style="width:100%">                    
            <h4 style="float:left">Address 2</h4>                                    
            <div id="Address2_Supplier" style="margin-left:100px"></div>     
        </div>                 

    </div>

    <div class="content_block">
        <a href="#" id="edit_supplier_trigger" class="button">EDIT SUPPLIER INFO</a>
    </div>

</div>

